
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProTable, TableDropdown } from '@ant-design/pro-components';
import { useEffect, useRef, useState } from 'react';
import request from 'umi-request';
import axios from "axios";
export const waitTimePromise = async (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

export const waitTime = async (time: number = 100) => {
  await waitTimePromise(time);
};
type GithubIssueItem = {
  name: string;
  room: string;
  type: string;
  faka: string;

  state: string;
  comments: number;
  created_at: string;
  updated_at: string;
  closed_at?: string;
};
const useLogcolumns: any = [  
  
  {  
    dataIndex: 'inedx',  
    valueType: 'index',  
    width: 48,  
  },  
  {  
    title: '房号',  
    dataIndex: 'Room',  
    ellipsis: true,  
    search: false,   
  },  
  {  
    title: '持卡人',  
    dataIndex: 'adminUse',  
    ellipsis: true,  
  },  
  {  
    title: '卡类型',  
    dataIndex: 'lei',  
    ellipsis: true,  
    valueType: 'select',  
    valueEnum: {  
      open: {  
        text: '管理卡',  
        status: 'Error',  
      },  
      processing: {  
        text: '卫生卡',  
        status: 'Processing',  
      },  
    },  
  },  
  {  
    title: '开锁时间',  
    dataIndex: 'kai',  
    ellipsis: true,  
    sorter: (a: { createdAt: number; }, b: { createdAt: number; }) => a.createdAt - b.createdAt,
  },  
  {  
    title: '开锁结果',  
    dataIndex: 'jie',  
    search: false, 
  }, 
  {  
    title: '卡ID',  
    dataIndex: 'card',    
    ellipsis: true,  
    search: false,   
  }, 
  {  
    title: '锁ID',  
    dataIndex: 'suoID',    
    ellipsis: true,  
    search: false,   
  }, 

  {  
    title: '控制器ID',  
    dataIndex: 'KongID',    
    ellipsis: true,  
    search: false,   
  }, 
  {  
    title: '操作',  
    valueType: 'option',  
    key: 'option',  
    render: (text: any, record: { url: string | undefined; }, _: any, action: any) => [  
      <a href={record.url} target="_blank" rel="noopener noreferrer" key="view">查看</a>,  
    ],  
  },  
];

const index:React.FC = () => {
  const [list, setlist] = useState([]); 

  const actionRef = useRef<ActionType>();
  useEffect(()=>{
    axios.get('/api/lockadmin')
    .then(({ data }) => {
     console.log(data.list)
       setlist(data.list)
    });
  },[])
  
const beforeSearchSubmit = (par: any) => {
  //par 就是你搜索表单输入的内容
  console.log(par)
}

  return (
    <>
      <ProTable<any>
      columns={useLogcolumns}
      actionRef={actionRef}
      cardBordered
      beforeSearchSubmit={beforeSearchSubmit}
      dataSource={list}
      editable={{
        type: 'multiple',
      }}
      columnsState={{
        persistenceKey: 'useRoom_log',
        persistenceType: 'localStorage',
        onChange(value) {
     
        },
      }}
      rowKey="id"
      search={{
        labelWidth: 'auto',
      }}
      options={{
        setting: {
          listsHeight: 400,
        },
      }}
      form={{
        // 由于配置了 transform，提交的参与与定义的不同这里需要转化一下
        syncToUrl: (values, type) => {
          if (type === 'get') {
            return {
              ...values,
              created_at: [values.startTime, values.endTime],
            };
          }
          return values;
        },
      }}
      pagination={false}
      dateFormatter="string"
      // headerTitle="高级表格"

    />
    </>
  )
}

export default index
